cmake_minimum_required(VERSION 3.14)

project(camera_qml VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
    set(CMAKE_PREFIX_PATH /opt/aarch64-dev/qt5)
else()
    set(CMAKE_PREFIX_PATH /home/alex/Qt5.12.8/5.12.8/gcc_64)
    include_directories(camera_qml /home/alex/arm-dev/include)
endif()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Multimedia)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Multimedia)
find_package(OpenCV REQUIRED)

set(PROJECT_SOURCES
        src/pointertypes.h src/pointertypes.cpp
        src/videosurface.h src/videosurface.cpp
        src/camera/basecapturer.h src/camera/basecapturer.cpp
        src/camera/videocapturer.h src/camera/videocapturer.cpp
        src/commonapi.h src/commonapi.cpp
        src/screenrecoder.h src/screenrecoder.cpp
        src/videosurface/basesurface.h src/videosurface/basesurface.cpp
        src/videorecord/baserecorder.h src/videorecord/baserecorder.cpp
        src/videosurface/shaderloader.h src/videosurface/shaderloader.cpp
        src/videorecord/videorecorder_cv.h src/videorecord/videorecorder_cv.cpp
        src/videorecord/videorecorder_ffmpeg.h src/videorecord/videorecorder_ffmpeg.cpp

        src/main.cpp
        qml.qrc
)

# 添加 mpp编码
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
     list(APPEND PROJECT_SOURCES  src/videorecord/videorecorder_mpp.h src/videorecord/videorecorder_mpp.cpp)
endif()

message( "sysytem processor:" ${CMAKE_SYSTEM_PROCESSOR})

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(camera_qml
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET camera_qml APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(camera_qml SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(camera_qml
          ${PROJECT_SOURCES}
        )
    endif()
endif()

target_include_directories(camera_qml PRIVATE ${OpenCV_INCLUDE_DIRS})

target_link_libraries(camera_qml
  PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick  Qt${QT_VERSION_MAJOR}::Multimedia avcodec avformat avutil avdevice swscale ${OpenCV_LIBS})

# aarch64 平台下链接 rockchip_mpp
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
    target_link_libraries(camera_qml PRIVATE rockchip_mpp)
endif()

set_target_properties(camera_qml PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

install(TARGETS camera_qml
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
    qt_import_qml_plugins(camera_qml)
    qt_finalize_executable(camera_qml)
endif()
